package com.zsgl.util;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

public class ClassUtil {
	
	public static List<Class<?>> getAllClass(String packageName) throws Exception {
		File[] files = new File(Thread.currentThread().getContextClassLoader().getResource(packageName.replace(".", "/")).getFile()).listFiles();
		List<Class<?>> classes = new ArrayList<Class<?>>();
		for (File file : files) {
			classes.add(Class.forName(packageName + "." + file.getName().replace(".class", "")));
		}
		return classes;
	}
	
	public static List<Class<?>> getAllInterface(String packageName) throws Exception {
		File file = new File(Thread.currentThread().getContextClassLoader().getResource(packageName.replace(".", "/")).getFile());
		File[] files = file.listFiles(new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return !(name.contains("Impl") || name.contains("Test"));
			}
		});
		List<Class<?>> classes = new ArrayList<Class<?>>();
		for (File f : files) {
			classes.add(Class.forName(packageName + "." + f.getName().replace(".class", "")));
		}
		return classes;
	}
	
}
